<?php
/**
 * app端首页
 * Author: lyun
 * Date: 2018/11/14
 * Created by Panxsoft.
 */


namespace App\Http\Controllers\Api\V1\App\Webview;

use App\Http\Controllers\ApiController;
use App\Http\Requests\App\AppHomeRequest;
use App\Http\Services\Api\V1\App\Webview\HomeService;
use App\Models\Setting;
use App\Models\Store\Store;
use App\Services\Locale\Language;
use App\Services\MobileApp\AppEnv;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HomeController extends ApiController
{
    const DEFAULT_APP_HOME = 'app'; // app首页webview地址。

    private $home_service;

    public function __construct()
    {
        $this->home_service = new HomeService;
    }

    /**
     * @param AppHomeRequest $request
     * @return array|\Illuminate\Http\Response
     * @throws \Exception
     */
    public function appHome(AppHomeRequest $request)
    {
        // todo 速度有点慢
        $layout_route = $request->layout_route ?: self::DEFAULT_APP_HOME;
        $app_home_setting = $this->home_service->getAppHomeSetting($layout_route);

        $theme = Setting::findConfigByKey(Setting::KEY_CONFIG_APP_THEME, AppEnv::storeId())->value ?? 'default';

        return $this->response(compact('app_home_setting', 'theme'));
    }
}
